/**
 * 二分查找
 */
public class BinarySearch {

    public static void main(String[] args) {
        int[] arr = {1,3,8,10,11,67,100};
        int index = binarySearch(arr,3);
        System.out.println(index);
    }

    public static int binarySearch(int[] arr, int target) {
        int l = 0;
        int h = arr.length - 1;
        while (l <= h) {
            int mid = l + (h - l) / 2;
            if (arr[mid] == target) return mid;
            if (arr[mid] > target) h = mid - 1;
            else l = mid + 1;
        }
        return -1;
    }
}
